#include "dicar.h"
void engine_init()
{
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);
  pinMode(ENA, OUTPUT);
  pinMode(ENB, OUTPUT);
  
  }
  //停止
  void car_stop()
  {
    digitalWrite(IN1,LOW);
    digitalWrite(IN3,LOW);
    digitalWrite(IN2,LOW);
    digitalWrite(IN4,LOW);
    }
    //前进
    void car_forward()
    {
      digitalWrite(IN1,HIGH);
      digitalWrite(IN3,HIGH);
      digitalWrite(IN2,LOW);
      digitalWrite(IN4,LOW);
      delay(500);
      car_stop();
      }
      //后退
      void car_backward()
      {
      digitalWrite(IN1,LOW);
      digitalWrite(IN3,LOW);
      digitalWrite(IN2,HIGH);
      digitalWrite(IN4,HIGH);
        delay(500);
      car_stop(); 
        }
        //左转
        void car_right()
        {
      digitalWrite(IN1,HIGH);
      digitalWrite(IN3,LOW);
      digitalWrite(IN2,LOW);
      digitalWrite(IN4,HIGH);
        delay(500);
      car_stop();
          }
          //右转
      void car_left()
          {
      digitalWrite(IN1,LOW);
      digitalWrite(IN3,HIGH);
      digitalWrite(IN2,HIGH);
      digitalWrite(IN4,LOW);
        delay(500);
      car_stop();
       
            }
            void car_ctrl(char ch)
            {
              switch(ch)
              {
                case 'f':
                car_forward();
               break;
                case 'b':
                car_backward();
                 break; 
                case 'l':
                car_left();
                 break; 
                case'r':
                car_right();
                 break;
                case 's':
                car_stop();
                 break;
                }
              }
